﻿@using Abp.Authorization.Users
@model PearAdmin.AbpTemplate.Admin.Models.Account.LoginFormViewModel
@{
    ViewBag.Title = L("LogIn");
}

@section styles{
    <link rel="stylesheet" href="~/css/views/login.css" asp-append-version="true"/>
}

<form class="layui-form" action="javascript:void(0);">
    <input type="hidden" name="returnUrl" value="@Model.ReturnUrl" />
    <input type="hidden" name="returnUrlHash" />
    <div class="layui-form-item">
        <img class="logo" src="~/images/logo.png" />
        <div class="title">AbpTemplate</div>
        <div class="desc">
            高 新 区 最 具 影 响 力 的 设 计 规 范 之 一
        </div>
    </div>
    <div class="layui-form-item">
        <input type="text" name="usernameOrEmailAddress" placeholder="@L("UserNameOrEmail"): admin" hover class="layui-input" required autofocus maxlength="@AbpUserBase.MaxEmailAddressLength" />
    </div>
    <div class="layui-form-item">
        <input type="password" name="password" placeholder="@L("Password"): 123qwe" hover class="layui-input" required maxlength="@AbpUserBase.MaxPlainPasswordLength" />
    </div>
    <div class="layui-form-item">
        <input type="checkbox" name="rememberMe" title="@L("RememberMe")" lay-skin="primary" checked>
    </div>
    <div class="layui-form-item">
        <button class="pear-btn pear-btn-primary login" lay-submit lay-filter="LAY-user-login-submit">@L("LogIn")</button>
    </div>
</form>

@section scripts{
    <script type="text/javascript">
        layui.use(['abp', 'form', 'element', 'jquery'], function () {
            var $ = layui.jquery;
            var abp = layui.abp;
            var form = layui.form;
            var element = layui.element;
            
            abp.multiTenancy.setTenantIdCookie(@ViewBag.TenantId);
            form.render();

            if(window !=top){
                top.location.href=location.href;
            }

            form.on('submit(LAY-user-login-submit)', function (data) {
                data.field.rememberMe = data.field.rememberMe == "on";//默认值是on
                var field = data.field; //获取提交的字段

                var waitIndex = layer.load(2);
                abp.ajax({
                    url: "@Url.Action("Login", "Account")",
                    data: JSON.stringify(field),
                    abpHandleError: false
                }).fail(function (jqXHR) {
                    layer.msg(jqXHR.message, { icon: 5 });
                }).always(function () {
                    layer.close(waitIndex);
                });

                return false;
            });
        })
    </script>
}